#include "TicTac.h"

TicTac::TicTac(void)
{
	n=m=1;
	x=9;
	y=5;
	i=1;
	vinst=0;
	drag=1;
}

void TicTac::printplan()
{
	
	Console::set_foreground_blue();

	cout << "|     |     |     |" << endl;
	cout << "|     |     |     |" << endl;
	cout << "|     |     |     |" << endl;
	cout << "-------------------" << endl;
	cout << "|     |     |     |" << endl;
	cout << "|     |     |     |" << endl;
	cout << "|     |     |     |" << endl;
	cout << "-------------------" << endl;
	cout << "|     |     |     |" << endl;
	cout << "|     |     |     |" << endl;
	cout << "|     |     |     |" << endl;

	
}



void TicTac::markor()
{
	i=1;
	while (drag <= 10){
		c = getch();

		if(c == 49 && (spelplan[n][m] != 'x') && (spelplan[n][m] != 'o'))
		{
			spelplan[n][m] = 'x';
			cout << "x";
			drag++;
		}

		else if (c == 48 && (spelplan[n][m] != 'x') && (spelplan[n][m] != 'o'))
		{
			spelplan[n][m] = 'o';
			cout << "o";
			drag++;
		}


		if (c == 56 && y > 1)
		{
			y = y - 4;
			Console::gotoxy(x, y);
			n = n-1;
		}

		else if (c == 50 && y < 9)
		{
			y = y + 4;
			Console::gotoxy(x, y);
			n = n + 1;
		}
		else if (c == 54 && x < 15)
		{
			x = x + 6;
			Console::gotoxy(x, y);
			m = m + 1;
		}
		else if (c == 52 && x > 3)
		{
			x = x - 6;
			Console::gotoxy(x, y);
			m = m - 1;
		}
		if (drag >= 6)
		{
			break;
		}

	}
}


	
int TicTac::vinnare()
	{
		for (i = 0; i < 3; i++) {
		if (spelplan[0][i] == spelarsymbol && spelplan[1][i] == spelarsymbol && spelplan[2][i] == spelarsymbol)
			{
				vinst = 1;
				return vinst;
		}
		if (spelplan[i][0] == spelarsymbol && spelplan[i][1] == spelarsymbol && spelplan[i][2] == spelarsymbol)
			{
				vinst = 1;
				return vinst;
		}
	}
		if (spelplan[0][0] == spelarsymbol && spelplan[1][1] == spelarsymbol && spelplan[2][2] == spelarsymbol)
		{
				vinst = 1;
				return vinst;
		}
		if (spelplan[0][2] == spelarsymbol && spelplan[1][1] == spelarsymbol && spelplan[2][0] == spelarsymbol)
			{
				vinst = 1;
				return vinst;
		}
}
